{include file="public/header"}
<title>订单编辑</title>
</head>
<body>


<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="form-member-add">
        <input type="hidden" name="order_id" value="{$order_id}">
        <input type="hidden" name="state" value="{$data['state']}">
        <input type="hidden" name="shifuid" value="">
        <div class="ch-row ch-info-form cl">
            <p class="flex1">开工时间：</p>
            <div class="flex2 ch-row ch-info-time input-group date" id='datetimepicker1'>
                <input type='text' class="form-control" name="sta_time" value=" <?php if(!empty($data['sta_time'])){?> {:date('Y-m-d H:i:s',$data.sta_time)}  <?php } ?>" />
                <p class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </p>
            </div>
        </div>
        <div class="ch-row ch-info-form cl">
            <p class="flex1">预计完工时间：</p>
            <div class="flex2 ch-row ch-info-time input-group date" id='datetimepicker2'>
                <input type='text' class="form-control" name="up_time" value=" <?php if(!empty($data['up_time'])){?> {:date('Y-m-d H:i:s',$data.up_time)}  <?php } ?>"/>
                <p class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </p>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1"></p>
            <span class="flex2" style="color: red;">预计完工时间：<?php if(!empty($c['gong'])){ echo date('Y-m-d H:i:s',strtotime(($c['gong']).'day',$c['crtime']));}?></span>
        </div>

        <div class="ch-row ch-info-form">
            <p class="flex1">添加师傅：</p>
            <div class="flex2" style="display: flex">
                <a class="ch-button ch-blue addshifu"  href="javascript:;" title="添加师傅">添加师傅</a>
            </div>
        </div>
        <div class="ch-row ch-info-form">
            <p class="flex1 "></p>
            <div class="flex2">
                <div class="title-border">
                    <div class="flex1">店铺</div>
                    <div class="flex1">编号</div>
                    <div class="flex1">姓名</div>
                    <div class="flex1">操作</div>
                </div>
                <div class="shifu">
                    {volist name='$data["shi"]' id='vo'}
                    <div class="content-border">
                        <div class="flex1">{$vo.store_name}</div>
                        <div class="flex1">{$vo.number}</div>
                        <div class="flex1">{$vo.username}</div>
                        <div class="flex1" disabled=""><button class="ch-button " disabled="disabled">删除</button></div>
                    </div>
                    {/volist}
                </div>
                
            </div>
        </div>

        <div class="ch-row ch-info-form">
            <p class="flex1"><span class="c-red">*</span>图片：</p>
            <div class="flex2">

                    <!--用来存放item-->
                    <div id="uploader-demo">
                        <!--用来存放item-->
                        <div id="filePicker">选择图片</div>
                        <div id="fileList" class="uploader-list">
                            <?php if(is_array($data['logo']))foreach($data['logo'] as $user){ ?>
                            <div id="" class="file-item thumbnail">
                                <div onclick="delParent(this)" style="cursor: pointer;background: url({$Think.DOMAIN_SRC}/static/h-ui/images/del.png) no-repeat;background-size:contain;height: 20px;width: 20px;position: absolute;z-index: 10;right: 5px;"></div>
                                <img style="width: 100px;height: 100px;" src="<?php echo $user ?>">
                                <input name="logo[]" type="hidden" value="<?php echo $user ?>">
                                <div class="info"></div>
                            </div>
                            <?php } ?>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <div class="ch-row ch-info-form" style="margin-top: 10px;">
            <p class="flex1">备注：</p>
            <div class="flex2">
                <textarea name="con" placeholder="请输入备注" class="form-control"><?php if(!empty($data['con'])){?> {$data.con}  <?php } ?></textarea>
            </div>
        </div>

        <div class="ch-row">
            <div class="flex1">
                <button class="btn btn-primary radius" style="width: 100%;" type="button"><i class="Hui-iconfont">&#xe632;</i> 提交</button>
            </div>
        </div>

    </form>
</article>
{include file="public/footer"}
<script>
    if("{is_array($data['shi'])}"){
        $('.ss').css('display','block');
    }
    $('#datetimepicker1').datetimepicker({
        format: 'yyyy-mm-dd hh:ii',  //显示格式可为yyyymm/yyyy-mm-dd/yyyy.mm.dd
        weekStart: 1,  	//0-周日,6-周六 。默认为0
        autoclose: true,
        startView: 3,  	//打开时显示的视图。0-'hour' 1-'day' 2-'month' 3-'year' 4-'decade'
        minView: 0,  	//最小时间视图。默认0-'hour'
        maxView: 4, 	//最大时间视图。默认4-'decade'
        todayBtn:true, 	//true时"今天"按钮仅仅将视图转到当天的日期。如果是'linked'，当天日期将会被选中。
        todayHighlight:true,	//默认值: false,如果为true, 高亮当前日期。
        initialDate: new Date(),	//初始化日期.默认new Date()当前日期
        forceParse: false,  	//当输入非格式化日期时，强制格式化。默认true
        bootcssVer:3,	//显示向左向右的箭头
        language: 'zh-CN' //语言
    });
    $('.radius').click(function () {
        var src="{:Url('index/order/yan')}";
        $.ajax({
            type: 'POST',
            url: src,
            dataType: 'json',
            data:$('form').serializeArray(),
            success: function (data) {
                var res=JSON.parse(data);
                if(res.code==200){
                    layer.msg(res.msg, {icon: 1, time: 2000}, function (index,layero) {
                        parent.location.reload()
                    });
                }else{
                    layer.msg(res.msg,{icon: 5,time:1000});
                }

            },
            error: function (data) {
                console.log(data.msg);
            },
        });

    });
    function ss(ss){
        $(ss).parent('.flex1').parent('.content-border').remove()
    }
    $('.addshifu').click(function () {
        var con=[];
        var cons=[];
        $.ajax({
            type: 'POST',
            url: "<?php echo UIP_SRC?>/shopowner/User/userlist",
            dataType: 'json',
            data: {},
            success: function (data) {
                if (data.code == 200) {
                    for (var i=0;i<data.data.length;i++)
                    {
                        con += `
                        <div class="content-border">
                            <div class="flex1">${data.data[i]['store_name']}</div>
                            <div class="flex1">${data.data[i]['number']}</div>
                            <div class="flex1">${data.data[i]['username']}</div>
                            <div class="flex1" style="display: none"><input name="shifuid[]" value="${data.data[i]['user_id']}"></div>
                            <div class="flex1 ch-checkbox" style="margin-right:0;"><input id="ch-checkbox" type="checkbox" name="reas" class="jie"><label for="ch-checkbox"></label></div>
                        </div>
                        `
                    }
                    con = `
                        <div class="title-border">
                            <div class="flex1">店铺</div>
                            <div class="flex1">编号</div>
                            <div class="flex1 ">姓名</div>
                            <div class="flex1"></div>
                        </div>
                        ${con}
                    `
                    var winWidth = $(window).width();
                    var areaWidth = "";
                    var areaHeight = "";
                    if( winWidth > 768 ){
                        areaWidth = "400px"
                        areaHeight = "400px"
                    } else {
                        areaWidth = '90%'
                        areaHeight = '80%'
                    }
                    layer.open({
                        title: '添加师傅',
                        area: [areaWidth, areaHeight],
                        btn:['保存','取消'],
                        content:'<div >'+con+'</div >',
                        btn1: function (index,layero) {
                            var arr = [];
                            $("input[name='reas']:checkbox").each(function (index) {
                                if ($(this).prop("checked") === true) {
                                    arr.push($(this).parent('.flex1').parent('.content-border'))
                                }
                            });
                            for (var i=0;i<arr.length;i++) {
                                arr[i][0].children[4].remove();
                                cons += `
                                <div class="content-border">
                                    ${arr[i][0].innerHTML}
                                    <div class="flex1"><a class="ch-button ch-blue" onclick="ss(this)" title="删除">删除</a></div>
                                </div>
                                `
                                
                            }

                            $('.shifu').append(cons);
                            $(".jie").remove();
                            // $('.ss').css('display','block');
                            layer.close(index);

                        },
                        btn2: function (index, layero) {
                            layer.close(index);
                        }

                    });
                } else {
                    layer.msg(res.msg, {icon: 5, time: 1000});
                }

            },
            error: function (data) {
                console.log(data.msg);
            },
        });



    });

    $("#img-change").click(function () {
        $("#file").click();
    });

    function delParent(object){
        $(object).parent().remove();
        count-=1;
    }
    var count=1;
    $(function(){
        var $list = $("#fileList");
        var uploader = WebUploader.create({
            auto: true,
            // 文件接收服务端。
            server: "{:Url('index/upload/upload_file')}",

            // 选择文件的按钮。可选。
            pick: '#filePicker',

            // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
            resize: false,
            duplicate:true,
            accept: {
                title: 'Images',
                extensions: 'gif,jpg,jpeg,bmp,png',
                mimeTypes: 'image/*'
            },
        });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail">' +
                '<div onclick="delParent(this)" style="cursor: pointer;background: url({$Think.DOMAIN_SRC}/static/h-ui/images/del.png) no-repeat;background-size:contain;height: 20px;width: 20px;position: absolute;z-index: 10;right: 5px;"></div>'+
                '<img style="width: 100px;height: 100px;">' +
                '<input name="logo[]" type="hidden" value="">'+
                '<div class="info">' + file.name + '</div>' +
                '</div>'
                ),
                $img = $li.find('img');


            // $list为容器jQuery实例
            $list.append( $li );

            // 创建缩略图
            // 如果为非图片文件，可以不用调用此方法。
            // thumbnailWidth x thumbnailHeight 为 100 x 100
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }

                $img.attr( 'src', src );
            }, 100, 100 );
        });



        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress span');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<p class="progress"><span></span></p>')
                    .appendTo( $li )
                    .find('span');
            }


            $percent.css( 'width', percentage * 100 + '%' );
        });
        var s=[];
        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
        uploader.on( 'uploadSuccess', function( file,res ) {
            var data = JSON.parse(res._raw);
            if(data.errcode==300){
                layer.alert(data.msg);
            }
            var url = data.data;
            count+=1;
            $( '#'+file.id).find("logo").attr("src",url);
            $( '#'+file.id).find("input").val(url);
            $( '#'+file.id ).addClass('upload-state-done');
        });

        // 文件上传失败，显示上传出错。
        uploader.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
                $error = $li.find('div.error');

            // 避免重复创建
            if ( !$error.length ) {
                $error = $('<div class="error"></div>').appendTo( $li );
            }

            $error.text('上传失败');
        });

        // 完成上传完了，成功或者失败，先删除进度条。
        uploader.on( 'uploadComplete', function( file ) {
            $( '#'+file.id ).find('.progress').remove();
        });
    });


</script>
</body>
</html>